document.addEventListener('DOMContentLoaded', function() {
    const links = document.querySelectorAll('.sidebar-link');
    links.forEach(link => {
        link.addEventListener('click', function(e) {
            e.preventDefault();
            const target = this.getAttribute('data-target');
            links.forEach(l => l.classList.remove('active'));
            this.classList.add('active');
            document.querySelectorAll('.content').forEach(c => c.classList.remove('active'));
            document.getElementById(`${target}-content`).classList.add('active');
            
            // 新增侧边栏切换时的平滑滚动动画
            document.querySelector('.content-container').style.transition = 'margin-left 0.3s ease';
        });
    });

    // 动态显示当前时间和系统运行时间
    function updateDateTime() {
        const now = new Date();
        const timeStr = now.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
        document.getElementById('current-time').textContent = timeStr;
        
        const startTime = new Date(document.documentElement.dataset.startTime);
        const runtime = Math.floor((now - startTime) / 1000);
        
        // 修改：将系统运行时间改为显示当前时间
        document.getElementById('system-runtime').textContent = timeStr;
    }

    document.documentElement.dataset.startTime = new Date().toISOString();
    setInterval(updateDateTime, 1000);
    updateDateTime();

    // 在DOMContentLoaded事件末尾添加
    fetch('https://ip-api.com/json')
        .then(response => response.json())
        .then(data => {
            document.getElementById('console-ip').textContent = data.query;
            document.getElementById('console-location').textContent = `${data.city}, ${data.region}`;
        });
    document.getElementById('console-device').textContent = 
        checkMobile() ? '移动设备' : '桌面设备';
});